/**
 * Copyright (c) 2011 The MITRE Corporation. All rights reserved.
 *
 * NOTICE
 * This software was produced for the U. S. Government
 * under Contract No. FA8721-11-C-0001, and is
 * subject to the Rights in Noncommercial Computer Software
 * and Noncommercial Computer Software Documentation Clause
 * (DFARS) 252.227-7014 (JUN 1995)
 */
package org.mitre.edxl.lib;

import java.net.URI;

/**
 * Container for content provided in a non-XML MIME type.
 *
 * @author Danny Gagne
 * @author Rob Gustafson
 * @author Brian Wilkins
 * @author Greg Kern
 */
public class NonXMLContent {
  private String mimeType; // required
  private Integer size; // optional
  private String digest; // optional
  private URI uri; // optional
  private String contentData; // optional

  /**
   * Get the value for the MIME Type.
   *
   * @return The String value of the MIME Type.
   */
  public String getMimeType() {
    return this.mimeType;
  }

  /**
   * Set the MIME Type value.
   *
   * @param val The value to set the MIME Type to.
   */
  public void setMimeType(String val) {
    this.mimeType = val;
  }

  /**
   * Get the value for the getSize.
   *
   * @return The Integer value of the Size.
   */
  public Integer getSize() {
    return this.size;
  }

  /**
   * Set the Size value.
   *
   * @param val The value to set the Size to.
   */
  public void setSize(Integer val) {
    this.size = val;
  }

  /**
   * Get the value for the Digest.
   *
   * @return The String value of the Digest.
   */
  public String getDigest() {
    return this.digest;
  }

  /**
   * Set the Digest value.
   *
   * @param val The value to set the Digest to.
   */
  public void setDigest(String val) {
    this.digest = val;
  }

  /**
   * Get the value for the URI.
   *
   * @return The URI value of the URI.
   */
  public URI getUri() {
    return this.uri;
  }

  /**
   * Set the URI value.
   *
   * @param val The value to set the URI to.
   */
  public void setUri(URI val) {
    this.uri = val;
  }

  /**
   * Get the value for the Base64 Binary.
   *
   * @return The String value of the Base64 Binary.
   */
  public String getBase64Binary() {
    return this.contentData;
  }

  /**
   * Set the Base64 Binary value.
   *
   * @param val The value to set the Base64 Binary to.
   */
  public void setBase64Binary(String val) {
    this.contentData = val;
  }

  /**
   * Returns a XML representation of the NonXMLContent object.
   *
   * @return A String of the XML representation of the NonXMLContent object.
   */
  public String toXML() {
    StringBuilder sb = new StringBuilder();

    sb.append("<mimeType>" + this.mimeType + "</mimeType>");
    if (this.size != null) {
      sb.append("<size>" + this.size.toString() + "</size>");
    }
    if (this.digest != null) {
      sb.append("<digest>" + this.digest + "</digest>");
    }
    if (this.uri != null) {
      sb.append("<uri>" + this.uri.toString() + "</uri>");
    }
    if (this.contentData != null) {
      sb.append("<contentData>");
      sb.append(this.contentData);
      // contentString=""; // invalidates the content, conserves memory (in
      // theory)
      this.contentData = "";
      sb.append("</contentData>");
    }

    return sb.toString();
  }
}
